import app


class loginAPI():
    def __init__(self):
        self.getImgCode_url = app.BASE_URL + '/common/public/verifycode1/'
        self.getSmsCode_url = app.BASE_URL + '/member/public/sendSms'
        self.register_url = app.BASE_URL + '/member/public/reg'
        self.login_url = app.BASE_URL + '/member/public/login'

    def getImgCode(self, session, r):
        url = self.getImgCode_url + r
        response = session.get(url)
        return response

    def getSmsCode(self, session, phone, imgCode):
        data = {"phone": phone, "imgVerifyCode": imgCode, "type": "reg"}
        url = self.getSmsCode_url
        response = session.post(url, data=data)
        return response

    def register(self, session, phone, pwd, invite_phone, imgCode="8888", SmsCode="666666", dyServer="on"):
        data = {"phone": phone, "password": pwd, "verifycode": imgCode, "phone_code": SmsCode,
                "dy_serve": dyServer, "invite_phone": invite_phone}
        url = self.register_url
        response = session.post(url, data)
        return response

    def login(self,session,keywords,password="test123"):
        data = {"keywords":keywords,"password":password}
        url = self.login_url
        response = session.post(url,data)
        return response